package net.ib.mtalk.network;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import net.ib.mtalk.constant.NetworkConstant.Session;

public class TcpNetworkQueue {

	private static ThreadPoolExecutor excutor = null;
	private static BlockingQueue<Runnable> queue = null;

	static {
		threadingStart();
	}
	
	public static BlockingQueue<Runnable> getInstance() {
		return queue;
	}
	
	/*	큐잉관리 시작	*/

	/**
	 * 스레드풀의 연산을 시작한다.
	 */
	public static void threadingStart() {
		if (queue == null) {
			queue = new LinkedBlockingQueue<Runnable>(Session.THREAD_BUCKET_SIZE);
		}
		if (excutor == null) {
			excutor = new ThreadPoolExecutor(
					Session.THREAD_POOL_SIZE, Session.THREAD_POOL_SIZE,
					Session.THREAD_ALIVE_TIME, TimeUnit.MILLISECONDS,
					queue);
		}
		excutor.prestartAllCoreThreads();
	}

	/**
	 * 스레드풀의 연산을 종료한다.
	 */
	public static void threadingEnd() {
		excutor.shutdown();
	}

	/*	큐잉관리 끝	*/

}
